var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s = e("nodePoolManager"),
    c = cc._decorator,
    l = c.ccclass,
    d = c.property,
    u = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (t.midNode = null), (t.joyBk = null), (t.maxR = 100), (t.joyCallBack = []), t;
        }
        return (
            a(t, e),
            (t.prototype.onLoad = function () {
                this.goBackMid();
            }),
            (t.prototype.start = function () {
                this.joyBk.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this),
                    this.joyBk.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this),
                    this.joyBk.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this),
                    this.joyBk.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this);
            }),
            (t.prototype.goBackMid = function () {
                this.midNode.setPosition(0, 0);
            }),
            (t.prototype.onTouchStart = function (e) {
                var t = this.node.convertToNodeSpaceAR(e.getLocation());
                this.clampPos(t),
                    this.midNode.setPosition(t.x, t.y),
                    (t = t.normalize()),
                    s.default.instance.gameModelInstance.onSnakeMoving(t);
            }),
            (t.prototype.onTouchMove = function (e) {
                var t = this.node.convertToNodeSpaceAR(e.getLocation());
                this.clampPos(t),
                    this.midNode.setPosition(t.x, t.y),
                    (t = t.normalize()),
                    s.default.instance.gameModelInstance.onSnakeMoving(t);
            }),
            (t.prototype.onTouchEnd = function (e) {
                this.goBackMid();
                var t = this.node.convertToNodeSpaceAR(e.getLocation());
                this.clampPos(t), (t = t.normalize()), s.default.instance.gameModelInstance.onSnakeMoving(t);
            }),
            (t.prototype.clampPos = function (e) {
                var t = e.mag();
                if (t > this.maxR) {
                    var o = this.maxR / t;
                    (e.x *= o), (e.y *= o);
                }
            }),
            (t.prototype.covertToAngle = function (e) {
                var t = Math.atan2(e.y, e.x);
                return cc.misc.radiansToDegrees(t);
            }),
            r([d({type: cc.Node, tooltip: "移动中心节点"})], t.prototype, "midNode", void 0),
            r([d({type: cc.Node, tooltip: "摇杆背景节点"})], t.prototype, "joyBk", void 0),
            r([d({type: cc.Integer, tooltip: "摇杆活动半径"})], t.prototype, "maxR", void 0),
            r([d({type: [cc.Component.EventHandler], tooltip: "摇杆移动回调"})], t.prototype, "joyCallBack", void 0),
            r([l], t)
        );
    })(cc.Component);
i.default = u;
